package com.test.common;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;

import com.alibaba.excel.EasyExcelFactory;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.metadata.Sheet;
import com.alibaba.excel.support.ExcelTypeEnum;
import com.mysql.jdbc.ExportControlled;
import com.test.model.WriteModel;

public class FileUtil {
		/**
		 * 使用easyExcel进行文件导出
		 * @throws IOException 
		 */
	
	public static void esportFile(OutputStream outputStream,List<WriteModel> writeModels) throws IOException{
		//OutputStream outputStream = new FileOutputStream("E://text.xls");
		ExcelWriter writer = new ExcelWriter(outputStream, ExcelTypeEnum.XLS,true);//EasyExcelFactory.getWriter(outputStream);
		//创建sheet
		Sheet sheet = new Sheet(1,0,WriteModel.class);
		sheet.setSheetName("菜单");
		writer.write(writeModels, sheet);
		writer.finish();
		//outputStream.close();
	}
		
		private static List<WriteModel> createModelList() {
			List<WriteModel> lists = new ArrayList<WriteModel>();
			for(int i=0;i<3;i++){
				WriteModel writeModel = new WriteModel();
				writeModel.setName("王勃");
				writeModel.setAccount("wangbo");
				writeModel.setPassword("123");
				lists.add(writeModel);
			}
			return lists;
		}
	
/*	public static void main(String[] args) throws IOException {
		esportFile();
	}*/
}
